﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MeTalker.Model;
using MeTalker.BLL;

public partial class Default_ChangePass : WebForm
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnChange_Click(object sender, EventArgs e)
    {
        UsersMod user = Session["UserSession"] as UsersMod;
        if (user != null) {

            if (string.IsNullOrEmpty(txtPass.Text))
            {
                Alert("旧密码不能为空");
                return;
            }
            if (string.IsNullOrEmpty(txtPass1.Text))
            {
                Alert("密码不能为空!");
                return;
            }
            if (!txtPass1.Text.Equals(txtPass2.Text))
            {
                Alert("两次密码不一致!");
                return;
            }
            string password = base.GetMD5(txtPass.Text);
            if (!user.Password.Equals(password))
            {
                Alert("旧密码不正确!");
                return;
            }

            user.Password = base.GetMD5(txtPass1.Text);
            if (UsersBLL.Update(user) > 0)
            {
                //Session["UserSession"] = user;
                Alert("密码修改成功!", "closePanel");
            }
            else
            {
                user.Password = password;
                Alert("密码修改失败!");
            }
        }
    }
}